<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>参与人员详细信息</title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>
<style type="text/css">
	.input_width { width:130px }
	.select_width { width:143px }
	.table_td td {border:0}
	.long_input{ width:642px }
</style>
<script type="text/javascript">
var type = "${param.type}";
var parentTable = parent.$("#"+"${param.parentTab}");	//父页面的表格
var selectRadio = $();									//父页面选中的单选框
var selectTr = $();										//父页面选中的行

if(type=="edit") {
	selectRadio = parentTable.find(":radio:checked");
	selectTr = selectRadio.parents("tr");
}

function setRadioSelectedValue(val,targetId,text){
	document.getElementById(targetId+"_name").value = text;
}

$(function(){
	$("#fragment-tab1 :text,#fragment-tab1 [type='date']").addClass("input_width");
	$("#fragment-tab1 select").addClass("select_width");
	
	var submitpsn=selectTr.find("[name$='submit_psn']");//标示是否是申报人
	
	if(type=="edit"){
		
		$("input:not(:radio:button),textarea").each(function(){

			var id=$(this).attr("name");
			if(id==null || id=="")
				return true;
			
			var parentObj=selectTr.find("[name$='/"+id+"']");
			var value="";
			if(parentObj.is("span"))
				value=parentObj.text();
			else
				value=parentObj.val();
			//if($(this).is("input"))//初始化input框 不包括radio
				$(this).val(value);
		});
		
		$(":radio").each(function(){//初始化radio框
			var name=$(this).attr("name");
		
			
			var value=$("[name='"+name+"_value']").val();
			if($(this).val()==value)
				$(this).attr("checked",true);
			
		});
		
		changeCardType();
		initDepartForComplete("org");
		if(submitpsn.length>0 && submitpsn.val()=="1"){//如果是申报人
			initResearch(selectTr,"researchTbl",false);
		}
		else{
			initResearch(selectTr,"researchTbl",true);
		}
		
		if(submitpsn.length>0 && submitpsn.val()=="1"){//如果是申报人
			$("input,select").each(function(){
				if(!$(this).attr("class")||$(this).attr("class").indexOf("notdisabled")==-1)
					$(this).attr("disabled","true");
			});
			$("#submit_psn_note").show();//如果是项目负责人，显示如何修改个人信息提示
			
			$("span[name='req_submitpsn']").show();//“通讯地址”申请人为必填
			$("input[name='address']").addClass("required");
			
			$("a,img").removeAttr("onclick");
			
			parent.$("#TB_ajaxWindowTitle").html("编辑申请人信息");
		}
		
	}
	
	function savePsn(){
		//填写检查接口
		//添加新行
		saveResearch("researchTbl");
		validate($("#fragment-tab1"),"个人信息");
		if(submitpsn.val()!="1"){
			validateResearch("researchTbl","prp");
		}
		if(!valResult()){
			irisValShowMsg($("#savePsn"));
			return false;
		}
		if(type=="add") {
			addNewRowDeal(parentTable);
		}
		
		var xmldate = prePareXmlDataStand($("#fragment-tab3"), "", "");
		$("#researches").val(xmldate.replace(/<researches.*?>|<\/researches>/g,""));
		
		$("input:not(:radio:button),textarea").each(function(){
			var id=$(this).attr("name");
			var parentObj=null;
			if(id==null || id=="")
				return true;
			//获得父页面的对象
			if(type=="add"){
				parentObj=parentTable.find("tr:last-child").find("[name$='/"+id+"']");
			}else if(type=="edit"){
				parentObj=selectTr.find("[name$='/"+id+"']");
			}
			if(parentObj!=null){
				if(parentObj.is("span")){
					parentObj.text($(this).val());	//将值写回父页面
				}
				else{
					parentObj.val($(this).val());
				}
			}
		});
		if(type=="add"){
			parentTable.find("tr:last :radio").attr("checked",true);
			if("${param.parentTab}"=="zh_persons")
				parent.setSubmitPsn();
		}
		if(confirm("保存成功，是否返回申请书页面"))
			parent.tb_remove();
		else if(type=="add"){
			type = "edit";
			selectRadio = parentTable.find(":radio:checked");	//父页面选中的单选框
			selectTr = selectRadio.parents("tr");				//父页面选中的行
		}
	}
	$("#savePsn").click(function(){
		setTimeout(savePsn,100);
	});
});

function loadAjaxSelect(selectId,url,params,varParm){
	$.ajax( {
		url : url,
		type : 'post',
		dataType:'json',
		data : params,
		success : function(data) {
			
			for(var i=0;i<data.length;i++){
				var value=data[i].id;
				var text=data[i].name;		
				$("#"+selectId).append("<option value='"+value+"'>"+text+"</option>");
				

			}
			if(type=="edit"){//如果是修改，才需要初始化select框的值
				var selectValue=$("[name='"+selectId+"_value']").val();
				$("#"+selectId+" option").each(function(i,obj){
					if($(obj).val()==selectValue){
						setTimeout(function() {
							$(obj).attr("selected",true);
						}, 1);
					}
				});
			}
			
			
		}
	});
	}

function setDegree(){
	
	var degreeText=$("#degree").children("option").filter(":selected").text();

	if(degreeText=="博士"){
		$("#degree_country_required").show();
		$("#degree_year_required").show();
		var itemClass=$("#degree_country").attr("class");
		if(itemClass.indexOf("required")==-1)
			$("#degree_country").attr("class",$("#degree_country").attr("class")+" required");
		
		itemClass=$("#degree_year").attr("class");
		if(itemClass.indexOf("required")==-1)
			$("#degree_year").attr("class",$("#degree_year").attr("class")+" required");
	}else{//关闭最高学位验证
		$("#degree_country_required").hide();
		$("#degree_year_required").hide();
		$("#degree_country").attr("class",$("#degree_country").attr("class").replace("required",""));
		$("#degree_year").attr("class",$("#degree_year").attr("class").replace("required",""));
	}
}

function changeCardType(){
	var cardTypeObj = $("[name='card_type_value']");
	var cardCodeObj = $("[name='card_code']");
	
	if(cardTypeObj.val()=="1"){
		cardCodeObj.addClass("idCard");
		cardCodeObj.attr("label","身份证");
	} else {
		cardCodeObj.removeClass("idCard");
		cardCodeObj.attr("label","证件号码");
	}
}

function changeTaiwanValue(name,text){
	var value = $("[name='"+name+"']:checked").val();
	$("[name='"+name+"_value']").val(value);
	$("[name='"+name+"_name']").val(text);
}

</script>

</head>
<body>

	<div id="tabnav">
		<ul>
			<li class="down" id="tab1" onclick="changeTab(this.id)">
					<a href="###"><span>个人信息</span></a>
			</li>
		</ul>
	</div>
	
	<div class="tab_box" id="fragment-tab1">
		<table class="t_css" width="100%" border="0" cellpadding="0" label="个人信息" cellspacing="1">
		<tr>
			<td nowrap align="right"><c:if test="${param.parentTab=='zh_persons'}" ><span class="color_red">*</span></c:if>姓名：</td>
			<td width="350px">
				<input name="zh_name" label="姓名" type="text" <c:choose><c:when test="${param.parentTab=='zh_persons'}" >required class="input_text required maxlength:25" </c:when><c:otherwise> class="input_text  maxlength:25" </c:otherwise></c:choose> value="" maxlength="25"/> 
			</td>
			<td align="right">
				<c:if test="${param.parentTab=='zh_persons'}" ><span class="color_red">*</span></c:if>性别：
			</td>
			<td>
				<input type="radio" id="gender_1" name="gender" label="性别" value="M" class="do<c:if test="${param.parentTab=='zh_persons'}" > required</c:if>"  onclick="initControlValue(this.id);setRadioSelectedValue(this.value,'gender_value','男')" />男
				&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" id="gender_2" name="gender" value="F" class="do"  onclick="initControlValue(this.id);setRadioSelectedValue(this.value,'gender_value','女')" />女
				<input type="hidden" name="gender_value_name" id="gender_value_name"  value=""/>
				<input type="hidden" name="gender_value" class="required" label="性别">
			</td>
		</tr>

		<tr>
			<td align="right">
				<c:if test="${param.parentTab=='zh_persons'}" >
					<span class="color_red">*</span>
				</c:if>证件类型：
			</td>
			<td>
				<c:choose>
					<c:when test="${param.parentTab=='zh_persons'}" >
						<cpt:select id="card_type" key="id_type_2" className="required" onChange="initControlValue(this.id);changeCardType();" label="证件类型"></cpt:select>
					</c:when><c:otherwise>
						<cpt:select id="card_type" key="id_type_2" onChange="initControlValue(this.id);changeCardType();"></cpt:select>
					</c:otherwise>
				</c:choose> 
				<input type="hidden" name="card_type_value" value="" label="证件类型"/>
				<input type="hidden" name="card_type_name"/>
			</td>
			<td align="right">
				<c:if test="${param.parentTab=='zh_persons'}" >
					<span class="color_red">*</span>
				</c:if>证件号码：
			</td>
			<td>
				<input type="text" name="card_code" label="证件号码" class="input_text required" maxlength="18" label="证件号码" />
			</td>
			
		</tr>
		<tr>
			<td align="right">
				<c:if test="${param.parentTab=='zh_persons'}" >
					<span class="color_red">*</span>
				</c:if>民族：
			</td>
			<td>
				
				<cpt:select id="ethnicity"  key="nation" className="required" onChange="initControlValue(this.id)"  label="民族"></cpt:select>
				<input type="hidden" name="ethnicity_value" value="" label="民族">
				<input type="hidden" name="ethnicity_name" value="">
			</td>
			<td align='right'>
			<c:if test="${param.parentTab=='zh_persons'}" >
					<span class="color_red">*</span>
				</c:if>出生日期：
			</td>
          	<td>
			
			<cpt:date id="birthday"  value="" className="required date beforeToday" label="出生日期"   name="birthday"></cpt:date> 
		    </td>
		</tr>
		
		
		
		<tr>
			<td align="right"><span class="color_red">*</span>职称：</td>
			<td>
				<cpt:select id="prof_title" key="title" onChange="initControlValue(this.id)" className="required" label="职称"></cpt:select>
				<input type="hidden" name="prof_title_value" label="职称" />
				<input type="hidden" name="prof_title_name" />
			</td>
			<td align="right"><span class="color_red">*</span>职务：
			</td>
			<td>
				<input type="text" label="职务" name="position" class="required" maxlength="50"/>
			</td>
		</tr>
		<tr>
		<td align="right"><span class="color_red">*</span>所学专业：</td>
		<td>
		<input type="text" label="所学专业" name="major" class="required" maxlength="50"/>
		</td>
		<td align="right"><span class="color_red">*</span>从事专业：</td>
		<td>
		<input type="text" label="从事专业" name="major_work" class="required" maxlength="50"/>
		</td>
		</tr>
		<tr>
		<td align="right"><span class="color_red">*</span>主要研究领域：</td>
		<td>
		<input type="text" label="主要研究领域" name="specialty" class="required" maxlength="50"/>
		</td>
		<td align="right"><span class="color_red">*</span>工作单位：</td>
		<td>
		<input type="text" label="工作单位" name="org_name" class="required" maxlength="50"/>
		</td>
		</tr>
		
		<tr>
			<td align="right">学历：</td>
			<td>
		 
				<cpt:select id="educate"  key="educate" onChange="initControlValue(this.id);"></cpt:select>
				<input type="hidden" name="educate_value" value="" label="最高学历">
				<input type="hidden" name="educate_name" value="">
				
			</td>
			<td align="right">学位：</td>
			<td >
				<cpt:select id="degree" key="degree" onChange="initControlValue(this.id)"></cpt:select>
				<input type="hidden" name="degree_value" label="学位"/>
				<input type="hidden" name="degree_name"/>
			</td>
		</tr>
	
	
		<tr>
			<td align="right"><span class="color_red">*</span>电子邮箱：</td>
			<td>
				<input type="text" name="email" required class="required email" label="电子邮箱" />
			</td>
			<td align="right"><span class="color_red">*</span>手机：</td>
			<td>
				<input type="text" name="mobile" maxlength="13" required class="required" onfocus="InitInput.setMobile(this)" label="手机" />
			</td>
		</tr>
		<tr>
			<td align="right"><span class="color_red">*</span>工作电话：</td>
			<td>
				<input type="text" name="tel_work" maxlength="50" required class="required" label="工作电话" />
			</td>
			<td align="right"><span class="color_red">*</span>项目分工：</td>
			<td><input type="text"  label="项目分工" name="work" required class="input_text required" maxlength="100" /></td>
		</tr>
		<tr>
			
			
			<td align="right"><span class="color_red">*</span>每年工作：</td>
			<td><input type="text" label="每年工作" name="working_time" onfocus="InitInput.setInt(this, 2)" required class="input_text required min:1 max:12"  />月</td>
		</tr>
	
		<tr id="submit_psn_note" style="display:none">
			<td colspan="4">
				<span class="color_gray">如果您需要修改个人信息， 请保存申请书后点击菜单"管理">"个人信息维护"完成修改。</span>
			</td>
		</tr>
	
	</table>
	</div>
	
	
	<table width="100%" align="center">
		<tr>
			<td><input type="button"  class="button_01 notdisabled" id="savePsn" value="保存">
				&nbsp;<input type="button" id="cancel" class="button_01 notdisabled" value="取消" onclick="parent.tb_remove();">
			</td>
		</tr>
	</table>
	<br />
</body>
</html>
